from datetime import datetime
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime, timezone, timedelta

db = SQLAlchemy()


def getDate():
    # 获取当前 UTC 时间对象
    utc_time = datetime.utcnow()
    # 创建澳洲时区的 timezone 对象
    au = timezone(timedelta(hours=10))
    # 将 UTC 时间对象转换为澳洲时区时间对象
    return utc_time.replace(tzinfo=timezone.utc).astimezone(au)


class EventModel(db.Model):
    __tablename__ = 'events'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(128))
    date = db.Column(db.String(128))
    _date = db.Column(db.String(128))
    from_time = db.Column(db.Integer, name='from')
    to_time = db.Column(db.Integer, name='to')
    location = db.Column(db.String(256))
    description = db.Column(db.String(512))
    last_update = db.Column(db.DateTime, name='last-update', default=datetime.utcnow, onupdate=getDate)
